const util = require('../../utils/util.js');
const win = util.getSystemHW();
Component({
  properties: {
    height: { // 属性名
      type: Number, // 类型（必填），目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: parseInt((win.windowWidth - 40)/2*16/9), // 属性初始值（可选），如果未指定则会根据类型选择一个
      observer: function(newVal, oldVal){} // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串
    },
    width: {
      type: Number,
      value:parseInt((win.windowWidth - 40)/2),
      observer: function(newVal, oldVal){}
    },
    imgClass:{
      type: String,
      value:''
    },
    imgUrl:{
      type: String,
      value:''
    },
    lbs:{
      type:Number,
      value:2
    },
    nums:{
      type:Number,
      value:0
    },
    callbackEvent:{
      type:String,
      value:''
    },
    dataId:{
      type:String,
      value:''
    },
    dataName:{
      type:String,
      value:''
    },
    dataDesc:{
      type:String,
      value:''
    },
    autorHead:{
      type:String,
      value:''
    },
    autorName:{
      type:String,
      value:''
    },
    dataLastCId:{
      type:String,
      value:''
    },
    dataLastMId:{
      type:String,
      value:''
    },
    dataPostIndex:{
      type:Number,
      value:0
    },
    dataDirect:{
      type:String,
      value:''
    }
  },
  data: {}, // 私有数据，可用于模版渲染
  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached: function(){},
  moved: function(){},
  detached: function(){},

  methods: {
    __imagetail_event: function(e){
      var thisObj = this;
      if(this.properties.callbackEvent&&this.properties.callbackEvent!==''){
        thisObj.triggerEvent(this.properties.callbackEvent,{
          dataId:this.properties.dataId,isTigger:true,
          dataName:this.properties.dataName,
          dataCover:this.properties.imgUrl,
          dataDesc:this.properties.dataDesc,
          autorHead:this.properties.autorHead,
          autorName:this.properties.autorName,
          dataLastCId:this.properties.dataLastCId,
          dataLastMId:this.properties.dataLastMId,
          dataIndex:this.properties.dataPostIndex,
          dataDirect:this.properties.dataDirect
        });
      }
    },
    __loadImageError: function(event){
      console.log(event.detail);
    },
    __loadImageFinished: function(event){
      var imageSize = util.imageUtil(event);
      if(this.properties.nums>0){
        var curWindowWidth = imageSize.windowWidth/this.properties.nums;
        var curImageWidth = curWindowWidth;
        var curImageHeight = (curImageWidth*imageSize.imageHeight)/imageSize.imageWidth;
        this.setData({
          width:curImageWidth,
          height:curImageHeight
        })
      }else{
        var curWindowWidth = imageSize.windowWidth;
        var curScanle = curWindowWidth/this.properties.width;
        var curImageWidth = this.properties.width;
        var curImageHeight = ((curWindowWidth*imageSize.imageHeight)/imageSize.imageWidth)/curScanle;
        this.setData({
          width:curImageWidth,
          height:curImageHeight>this.properties.height?this.properties.height:curImageHeight
        })
      }
    }
  }

})
